package com.luoxiang.socialandroid.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.luoxiang.socialandroid.R;
import com.luoxiang.socialandroid.app.MyAppliaction;
import com.luoxiang.socialandroid.bean.THost;

import java.util.List;

public class FansAdapter extends RecyclerView.Adapter<FansAdapter.ViewHolder> {
    private List<THost> list;
    private String url = "https://dahuixiong.oss-cn-shenzhen.aliyuncs.com/";

    public FansAdapter(List<THost> list) {
        this.list = list;
    }

    @NonNull
    @Override
    public FansAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_follow, parent, false);
        FansAdapter.ViewHolder holder = new FansAdapter.ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull FansAdapter.ViewHolder holder, int position) {
        THost hostBean = list.get(position);
        Glide.with(MyAppliaction.getContext())
                .load(url + hostBean.getIcon())
                .into(holder.im1_follow);
        if (hostBean.getIdentity() == 10) {
            holder.im2_follow.setImageResource(R.mipmap.icon_huangjin);
        } else if (hostBean.getIdentity() == 20) {
            holder.im2_follow.setImageResource(R.mipmap.icon_bojin);
        } else if (hostBean.getIdentity() == 30) {
            holder.im2_follow.setImageResource(R.mipmap.icon_zuanshi);
        } else {

            holder.im2_follow.setVisibility(View.GONE);
        }
        holder.tx1_follow.setText(hostBean.getName());
        holder.tx2_follow.setText(hostBean.getPersionSign());
    }

    @Override
    public int getItemCount() {
        try {
            return list.size();
        } catch (Exception e) {
            return 0;
        }
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView im1_follow, im2_follow;
        private TextView tx1_follow, tx2_follow;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            im1_follow = itemView.findViewById(R.id.im1_follow);
            im2_follow = itemView.findViewById(R.id.im2_follow);
            tx1_follow = itemView.findViewById(R.id.tx1_follow);
            tx2_follow = itemView.findViewById(R.id.tx2_follow);
        }
    }
}
